<!DOCTYPE html>
<meta charset="utf-8">
<title>Attributes are not Nodes and should not be accepted where they are</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-core-changes">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
"use strict";

test(() => {

  const attribute = document.createAttribute("newattribute");

  const notOnAttrs = ["ELEMENT_NODE", "ATTRIBUTE_NODE", "TEXT_NODE", "CDATA_SECTION_NODE", "ENTITY_REFERENCE_NODE",
    "ENTITY_NODE", "PROCESSING_INSTRUCTION_NODE", "COMMENT_NODE", "DOCUMENT_NODE",
    "DOCUMENT_TYPE_NODE", "DOCUMENT_FRAGMENT_NODE", "NOTATION_NODE", "nodeType", "baseURI",
    "ownerDocument", "parentNode", "parentElement", "hasChildNodes", "childNodes", "firstChild",
    "lastChild", "previousSibling", "nextSibling", "normalize", "cloneNode", "isEqualNode",
    "DOCUMENT_POSITION_DISCONNECTED", "DOCUMENT_POSITION_PRECEDING", "DOCUMENT_POSITION_FOLLOWING",
    "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_CONTAINED_BY",
    "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC", "compareDocumentPosition", "contains",
    "lookupPrefix", "lookupNamespaceURI", "isDefaultNamespace", "insertBefore", "appendChild",
    "replaceChild", "removeChild"];

  for (const prop of notOnAttrs) {
    assert_false(prop in attribute, `${prop} should not exist on attribute instances`);
    assert_false(prop in Attr.prototype, `${prop} should not exist on Attr.prototype`);
  }

}, "Attrs do not have node properties or methods");

test(() => {

  const parent = document.createElement("p");

  const attribute = document.createAttribute("newattribute");
  assert_throws(new TypeError(), () => {
    parent.appendChild(attribute);
  });

}, "appendChild with an attribute as the child should fail");

test(() => {

  const parent = document.createElement("p");
  parent.appendChild(document.createElement("span"));

  const attribute = document.createAttribute("newattribute");
  assert_throws(new TypeError(), () => {
    parent.replaceChild(attribute, parent.firstChild);
  });

}, "replaceChild with an attribute as the child should fail");

test(() => {

  const parent = document.createElement("p");
  parent.appendChild(document.createElement("span"));

  const attribute = document.createAttribute("newattribute");
  assert_throws(new TypeError(), () => {
    parent.insertBefore(attribute, parent.firstChild);
  });

}, "insertBefore with an attribute as the child should fail");

</script>
